const {
	Provider
} = require("../model/model.js");

const ProviderDao = {
	add(provInfo) {
		const provider = new Provider(provInfo);
		return provider.save();
	},
	findByCode(condition){
		return Provider.findOne({prov_code:condition});
	},
	//根据页码查询
	findByPage(page) {
		//		const pageSize = 4;
		//		return Provider.find({}).limit(pageSize).skip((page - 1) * pageSize);
		return Provider.find();
	},
	//根据输入的供应商名称查询
	findByProv_name(prov_nameInfo) {
		const reg = new RegExp(prov_nameInfo);
		return Provider.find({
			$or: [{
				prov_name: {
					$regex: prov_nameInfo
				}
			}]
		});
	},
	modify(_id, modifyInfo) {
		return Provider.updateOne({
			_id
		}, modifyInfo);
	},
	//删除
	delete(_id) {
		return Provider.remove({
			_id
		});
	}
}

module.exports = ProviderDao;